import { defineStore } from 'pinia'
import { useRequest } from '~/composables/useRequest'

export const useIntroduceStore = defineStore('introduceStore', () => {
  const { requestGet, requestPost } = useRequest()
  const state = reactive({
    introduceList: [],
    introduceDetail: {},
  })

  return {
    ...toRefs(state),
    async initIntroduceList(curPage = 1, perPage = 10) {
      const { data } = await requestGet(`/app/game/all/${curPage}/${perPage}`, {})
      state.introduceList = data.data
      return data
    },
    async initIntroduceDetail(urlName: string) {
      const { data } = await requestGet(`/app/game/detail`, {
        params: {
          //因为/xx被route解析之后只剩下 xx了 但是接口要传的是/xx 所以要补一个/
          urlName: `/${urlName}`,
        },
      })
      state.introduceDetail = data
    },
  }
})
